package com.gdit.zax.servlet;

import java.io.IOException;
import java.sql.Connection;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.gdit.zax.dao.FreebackDao;
import com.gdit.zax.entitys.Freeback;
import com.gdit.zax.factory.DAOFactory;
import com.gdit.zax.utils.DBUtil;
import com.gdit.zax.utils.O;
import com.gdit.zax.utils.TextUtil;

/**
 * 提交意见
 * @author lenovo
 *
 */
public class Retroaction extends HttpServlet {
	//http://pingkgs3pc:8080/zuiaixue/retroaction?suggestion=fgfdsg&connection=1353654564
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		this.doPost(request, response);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		String suggestion = request.getParameter("suggestion");
		String cantact = request.getParameter("connection");
		
		if (TextUtil.isEmpty("suggestion")) {
			O.printFail(response, 1, "请填写意见!");
			return;
		}
		
		Connection conn = DBUtil.getConnection();
		if (conn==null) {
			O.printFail(response, 1000, "数据库连接失败!");
			return;
		}
		
		DAOFactory dao  = DAOFactory.init(conn, request, response);
		FreebackDao udao = dao.getFreebackDao();
		Freeback fb = new Freeback();
		fb.setContent(suggestion);
		fb.setCantact(cantact);
		
		if (udao.addFreebak(fb)){
			O.printSuccess(response,"意见提交成功!");
		} else {
			O.printFail(response, 1, "意见提交失败!");
		}
		
	}

}
